#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

typedef struct
{
    int r[20];
    int length;
}SqList;

int Partition(SqList &L,int low,int high)
{
    L.r[0]=L.r[low];
    while(low<high)
    {
        while(L.r[high]>=L.r[0]&&low<high) high--;
        L.r[low]=L.r[high];
        while(L.r[low]<=L.r[0]&&low<high) low++;
        L.r[high]=L.r[low];
    }
    L.r[low]=L.r[0];
    for(int i=1;i<=L.length;i++)
        printf("%d ",L.r[i]);
    printf("\n");
    return low;
}
void QSort(SqList &L,int low,int high)
{
    int p;
    if(low<high)
    {
       p=Partition(L,low,high);
       QSort(L,low,p-1);
       QSort(L,p+1,high);
    }
}
int main()
{
    int n,i;
    SqList L;
    scanf("%d",&n);
    L.length=n;
    for(i=1;i<=n;i++)
        scanf("%d",&L.r[i]);
    QSort(L,1,n);
    return 0;
}
